mudbox::Vector Class Reference

#include <math.h>

List of all members.


Detailed Description

Represents a 3D vector or point with S23E8 floating point elements.

Public Member Functions

  Vector (void) throw ()
  Constructs the vector with zero values.
  Vector (float fX, float fY, float fZ=0.0f) throw ()
  Constructs the vector with specified values.
  Vector (const Vector &vVector) throw ()
  Copy constructor.
  Vector (const char *pVector) throw ()
  Construct the vector from a pointer to 8bit signed data.
  Vector (const short *pVector) throw ()
  Construct the vector from a pointer to 16bit signed data.
Vector Set (float fX, float fY, float fZ) throw ()
  Sets the values of the vector elements and returns the vector.
Vector Clear (void) throw ()
  Zeros all the components of the Vector, then returns it.
Vector Normalize (void) throw ()
  Normalizes the vector and returns it.
Vector NormalizeApprox (void) throw ()
  Normalizes the vector and returns it.
Vector  Normalized (void) const throw ()
  Returns a normalized version of the vector, without changing this vector.
Vector MakeOrthogonal (const Vector &vBase)
  Makes this vector orthogonal to the given vBase vector and normalizes it. Returns the vector.
Vector SetLength (float fLength)
  Sets the vector to the given length, without changing its direction.
Vector RotateOrthogonal (const Vector &vBase)
  Rotates this vector to be orthogonal to vBase without changing its length, and returns it.
float  LengthSquare (void)
  Returns the square of the length of the vector.
float  Length () const throw ()
  Returns the length of the vector.
float  Length2D () const throw ()
  Returns the 2D length of the vector, ignoring the z element.
float  DistanceFrom (const Vector &v) const
  Returns the distance between two points (this and another, represented as Vector objects).
float  DistanceFromLine (const Vector &v0, const Vector &v1) const
  Returns the shortest distance between this point and a line defined by two other points (all points represented by vector objects).
const Vector Relocate2D (const Vector &v0, const Vector &v1)
  Converts this (2d) vector to represent itself as a linear combination of the supplied basis vectors. Returns the result.
void  Relocate (const Vector &v0, const Vector &v1, const Vector &v2)
  Converts this vector to represent itself as a linear combination of the supplied basis vectors.
bool  Relocate2DQuad (const Vector &v0, const Vector &v1, const Vector &v2, const Vector &v3)
  This operation calculates the baricentric coordinates inside a quad where the quad corners are v0,v1,v2,v3.
float  AngleCos (const Vector &v1) const throw ()
  Returns the cosine of the angle between this vector and the one passed in.
Vector  Minimum (const Vector &o)
  Returns the minimum of this and the argument vector.
Vector  Maximum (const Vector &o)
  Returns the maximum of this and the argument vector.
Vector  operator- (void) const throw ()
  Returns the inverse of the vector.
Vector  operator+ (float f) const throw ()
  Returns the sum of a vector and a scalar.
Vector  operator+ (const Vector &v) const throw ()
  Returns the sum of two vectors.
Vector  operator- (const Vector &v) const throw ()
  Returns the difference between two vectors/points.
Vector  operator * (const Vector &v) const throw ()
  Returns the product of two vectors by components.
Vector  operator * (float f) const throw ()
  Returns the product of the vector and a scalar.
Vector  operator/ (const Vector &v) const throw ()
  Returns the quotient of two vectors by components.
Vector  operator/ (float f) const throw ()
  Returns the quotient of a vector and a scalar.
Vector  operator * (int i) const throw ()
  Returns the product of a vector and an integer.
Vector  operator/ (int i) const throw ()
  Returns the quotient of a vector and an integer.
Vector  operator/ (unsigned int i) const throw ()
  Returns the quotient of a vector and an unsigned integer.
float  operator| (const Vector &v) const throw ()
  Returns the dot product of two vectors.
Vector  operator & (const Vector &v) const
  Returns the cross product of two vectors.
bool  operator== (const Vector &v) const throw ()
  Returns true if the two vectors are identical, false otherwise.
bool  operator!= (const Vector &v) const throw ()
  Returns true if the two vectors are different, false otherwise.
  operator bool (void) const throw ()
  Returns true if the vector is not a zero vector, false otherwise.
bool  operator! (void) const throw ()
  Returns true if the vector is a zero vector, false otherwise.
Vector operator= (const Vector &v)
  Sets this vector to equal another one and returns it.
Vector operator<< (const Vector &v)
  Sets this vector to equal another one and returns it.
Vector operator-= (const Vector &v) throw ()
  Subtracts the component values of another vector from this one's, and returns the result.
Vector operator+= (const Vector &v) throw ()
  Adds another vector to this one and returns the result.
Vector operator *= (float f)
  Multiplies the components of the vector with a scalar value and returns the result.
Vector operator *= (const Vector &v)
  Multiplies the vector with another vector by components and returns the result.
Vector operator/= (float f)
  Divides the vector by a scalar and returns the result.
float &  operator[] (int i) throw ()
  Returns a individual components of the vector.
float &  operator[] (unsigned int i) throw ()
  Returns a component of the vector.
  operator const float * (void) const
  Returns a pointer to the data of the vector. Do not delete this pointer.

Constructor & Destructor Documentation

mudbox::Vector::Vector void   )  throw () [inline]
 

Constructs the vector with zero values.

00030 { x = y = z = 0.0f; };
mudbox::Vector::Vector float  fX,
float  fY,
float  fZ = 0.0f
throw () [inline]
 

Constructs the vector with specified values.

00034     { x = fX; y = fY; z = fZ; };
mudbox::Vector::Vector const Vector vVector  )  throw () [inline]
 

Copy constructor.

00038     { x = vVector.x; y = vVector.y; z = vVector.z; };
mudbox::Vector::Vector const char *  pVector  )  throw () [inline]
 

Construct the vector from a pointer to 8bit signed data.

The array must have at least 3 elements, with values in the range -127 to +127.

00044     { x = pVector[0]*(1.0f/127.0f); y = pVector[1]*(1.0f/127.0f); z = pVector[2]*(1.0f/127.0f); };
mudbox::Vector::Vector const short *  pVector  )  throw () [inline]
 

Construct the vector from a pointer to 16bit signed data.

The array must have at least 3 elements in the range -32767 to +32767.

00049     { x = pVector[0]*(1.0f/32767.0f); y = pVector[1]*(1.0f/32767.0f); z = pVector[2]*(1.0f/32767.0f); };

Member Function Documentation

Vector& mudbox::Vector::Set float  fX,
float  fY,
float  fZ
throw () [inline]
 

Sets the values of the vector elements and returns the vector.

00053     { x = fX; y = fY; z = fZ; return *this; };
Vector& mudbox::Vector::Clear void   )  throw () [inline]
 

Zeros all the components of the Vector, then returns it.

00057     { return Set( 0.0f, 0.0f, 0.0f ); };
Vector& mudbox::Vector::Normalize void   )  throw ()
 

Normalizes the vector and returns it.

If the vector is zero length, it is set to (0,1,0)

Vector& mudbox::Vector::NormalizeApprox void   )  throw ()
 

Normalizes the vector and returns it.

If the vector is zero length, it is set to (0,1,0) TO BE REMOVED. This was an experiment at improving speed in exchange for accurracy.

Vector mudbox::Vector::Normalized void   )  const throw ()
 

Returns a normalized version of the vector, without changing this vector.

Vector& mudbox::Vector::MakeOrthogonal const Vector vBase  ) 
 

Makes this vector orthogonal to the given vBase vector and normalizes it. Returns the vector.

The resulting vector will lie on the plane defined by the original value of this vector, and vBase.

Vector& mudbox::Vector::SetLength float  fLength  )  [inline]
 

Sets the vector to the given length, without changing its direction.

If the vector is of zero length, then it is arbitrarily made parallel to the Y axis.

00086     { Normalize(); operator *=( fLength ); return *this; };
Vector& mudbox::Vector::RotateOrthogonal const Vector vBase  )  [inline]
 

Rotates this vector to be orthogonal to vBase without changing its length, and returns it.

The resulting vector will lie on the plane defined by the original value of this vector, and vBase.

00095     { float fLen = Length(); MakeOrthogonal( vBase ); SetLength( fLen ); return *this; };
float mudbox::Vector::LengthSquare void   )  [inline]
 

Returns the square of the length of the vector.

00099 { return x*x+y*y+z*z; };
float mudbox::Vector::Length  )  const throw ()
 

Returns the length of the vector.

float mudbox::Vector::Length2D  )  const throw ()
 

Returns the 2D length of the vector, ignoring the z element.

float mudbox::Vector::DistanceFrom const Vector v  )  const [inline]
 

Returns the distance between two points (this and another, represented as Vector objects).

00109 { return operator -(v).Length(); };
float mudbox::Vector::DistanceFromLine const Vector v0,
const Vector v1
const
 

Returns the shortest distance between this point and a line defined by two other points (all points represented by vector objects).

const Vector& mudbox::Vector::Relocate2D const Vector v0,
const Vector v1
 

Converts this (2d) vector to represent itself as a linear combination of the supplied basis vectors. Returns the result.

This function works in 2d, ignoring the Z component of all the vectors. The supplied basis vectors must not be parallel.

This method figures out how to express this vector (x,y) as a linear combination of the two vector arguments. X is set to the multiplier on the first vector, and Y to the multiplier on the second vector. So the original vector could be reconstructed from the final one like this: original = x*v0 + y*v1

void mudbox::Vector::Relocate const Vector v0,
const Vector v1,
const Vector v2
 

Converts this vector to represent itself as a linear combination of the supplied basis vectors.

This method figures out how to express this vector (x,y,z) as a linear combination of the three vector arguments. X is set to the multiplier on the first vector, Y to the multiplier on the second vector, and Z to the multiplier on the third. The supplied basis vectors must not be parallel. So the original vector could be reconstructed from the final one like this: original = x*v0 + y*v1 + z*v2

bool mudbox::Vector::Relocate2DQuad const Vector v0,
const Vector v1,
const Vector v2,
const Vector v3
 

This operation calculates the baricentric coordinates inside a quad where the quad corners are v0,v1,v2,v3.

2d points in this function are represented by 3d Vector objects, with the Z component ignored. This function works in 2d only. If v0, v1, v2 and v3 are the corners of a quad in a 2d space (such as UV space), and this object's (x,y) coordinates represent a point inside that quad, then this function will calculate the baricentric coordinates inside the quad (v0 and v3 are opposite corners). After this operation the following code can calculate the original value stored in the vector (this can help you understand what the function does):

        Vector vEdgeA = v1-v0;
        Vector vEdgeB = v3-v2;
        Vector vPointA = v0+vEdgeA*x;
        Vector vPointB = v2+vEdgeB*x;
        Vector vEdge = vPointB-vPointA;
        Vector vValueBeforeOperation = vPointA+vEdge*y;
float mudbox::Vector::AngleCos const Vector v1  )  const throw () [inline]
 

Returns the cosine of the angle between this vector and the one passed in.

00166     { return Vector(*this).Normalize()|Vector(v1).Normalize(); };
Vector mudbox::Vector::Minimum const Vector o  )  [inline]
 

Returns the minimum of this and the argument vector.

Minimums are calculated individually for z, y, and z.

00172     { return Vector( Min(x, o.x), Min(y, o.y), Min(z, o.z) ); };
Vector mudbox::Vector::Maximum const Vector o  )  [inline]
 

Returns the maximum of this and the argument vector.

Maximums are calculated individually for z, y, and z.

00177     { return Vector( Max(x, o.x), Max(y, o.y), Max(z, o.z) ); };
Vector mudbox::Vector::operator- void   )  const throw () [inline]
 

Returns the inverse of the vector.

00181     { return Vector( -x, -y, -z ); };
Vector mudbox::Vector::operator+ float  f  )  const throw () [inline]
 

Returns the sum of a vector and a scalar.

(The scalar is added to each component individually).

00186     { return Vector( x+f, y+f, z+f ); };
Vector mudbox::Vector::operator+ const Vector v  )  const throw () [inline]
 

Returns the sum of two vectors.

00190     { return Vector( x+v.x, y+v.y, z+v.z ); };
Vector mudbox::Vector::operator- const Vector v  )  const throw () [inline]
 

Returns the difference between two vectors/points.

00194     { return Vector( x-v.x, y-v.y, z-v.z ); };
Vector mudbox::Vector::operator * const Vector v  )  const throw () [inline]
 

Returns the product of two vectors by components.

00198     { return Vector( x*v.x, y*v.y, z*v.z ); };
Vector mudbox::Vector::operator * float  f  )  const throw () [inline]
 

Returns the product of the vector and a scalar.

00202     { return Vector( x*f, y*f, z*f ); };
Vector mudbox::Vector::operator/ const Vector v  )  const throw () [inline]
 

Returns the quotient of two vectors by components.

00206     { return Vector( x/v.x, y/v.y, z/v.z ); };
Vector mudbox::Vector::operator/ float  f  )  const throw () [inline]
 

Returns the quotient of a vector and a scalar.

00210     { return operator *( 1.0f/f ); };
Vector mudbox::Vector::operator * int  i  )  const throw () [inline]
 

Returns the product of a vector and an integer.

00214     { return operator *( float(i) ); };
Vector mudbox::Vector::operator/ int  i  )  const throw () [inline]
 

Returns the quotient of a vector and an integer.

00218     { return operator /( float(i) ); };
Vector mudbox::Vector::operator/ unsigned int  i  )  const throw () [inline]
 

Returns the quotient of a vector and an unsigned integer.

00222     { return operator /( float(i) ); };
float mudbox::Vector::operator| const Vector v  )  const throw () [inline]
 

Returns the dot product of two vectors.

00226     { return x*v.x+y*v.y+z*v.z; };
Vector mudbox::Vector::operator & const Vector v  )  const [inline]
 

Returns the cross product of two vectors.

00230     {
00231         Vector vR;
00232         vR.m_fX = m_fY*v.m_fZ-m_fZ*v.m_fY;
00233         vR.m_fY = m_fZ*v.m_fX-m_fX*v.m_fZ;
00234         vR.m_fZ = m_fX*v.m_fY-m_fY*v.m_fX;
00235         return vR;
00236     };
bool mudbox::Vector::operator== const Vector v  )  const throw () [inline]
 

Returns true if the two vectors are identical, false otherwise.

00241     { return x == v.x && y == v.y && z == v.z; };
bool mudbox::Vector::operator!= const Vector v  )  const throw () [inline]
 

Returns true if the two vectors are different, false otherwise.

00245     { return !operator ==( v ); };
mudbox::Vector::operator bool void   )  const throw () [inline]
 

Returns true if the vector is not a zero vector, false otherwise.

00248 { return x || y || z; };
bool mudbox::Vector::operator! void   )  const throw () [inline]
 

Returns true if the vector is a zero vector, false otherwise.

00251 { return !operator bool(); };
Vector& mudbox::Vector::operator= const Vector v  )  [inline]
 

Sets this vector to equal another one and returns it.

00255     { x = v.x; y = v.y; z = v.z; return *this; };
Vector& mudbox::Vector::operator<< const Vector v  )  [inline]
 

Sets this vector to equal another one and returns it.

00259     { x = v.x; y = v.y; z = v.z; return *this; };
Vector& mudbox::Vector::operator-= const Vector v  )  throw () [inline]
 

Subtracts the component values of another vector from this one's, and returns the result.

00264     { x-=v.x; y-=v.y; z-=v.z; return *this; };
Vector& mudbox::Vector::operator+= const Vector v  )  throw () [inline]
 

Adds another vector to this one and returns the result.

00268         { x+=v.x; y+=v.y; z+=v.z; return *this; };
Vector& mudbox::Vector::operator *= float  f  )  [inline]
 

Multiplies the components of the vector with a scalar value and returns the result.

00272 { x *= f; y *= f; z *= f; return *this; };
Vector& mudbox::Vector::operator *= const Vector v  )  [inline]
 

Multiplies the vector with another vector by components and returns the result.

00277         { x *= v.x; y *= v.y; z *= v.z; return *this; };
Vector& mudbox::Vector::operator/= float  f  )  [inline]
 

Divides the vector by a scalar and returns the result.

00280 { return operator *=( 1.0f/f ); };
float& mudbox::Vector::operator[] int  i  )  throw () [inline]
 

Returns a individual components of the vector.

Parameters:
i  [in] Allowed range: 0 to 2.
00284                                        :  0 to 2.
00285         ) throw() { return m_aCoors[i]; };
float& mudbox::Vector::operator[] unsigned int  i  )  throw () [inline]
 

Returns a component of the vector.

Parameters:
i  [in] Allowed range: 0 to 2.
00289                                                :  0 to 2.
00290         ) throw() { return m_aCoors[i]; };
mudbox::Vector::operator const float * void   )  const [inline]
 

Returns a pointer to the data of the vector. Do not delete this pointer.

00293 { return &x; };

Member Data Documentation

float mudbox::Vector::m_fX
 
float mudbox::Vector::m_fY
 
float mudbox::Vector::m_fZ
 
float mudbox::Vector::x
 
float mudbox::Vector::y
 
float mudbox::Vector::z
 
float mudbox::Vector::m_aCoors[3]
 

mudbox::Vector mudbox::Vector mudbox::Vector mudbox::Vector mudbox::Vector mudbox::Vector mudbox::Vector mudbox::Vector mudbox::Vector mudbox::Vector
mudbox::Vector mudbox::Vector mudbox::Vector mudbox::Vector mudbox::Vector mudbox::Vector mudbox::Vector mudbox::Vector mudbox::Vector mudbox::Vector